﻿using GYCTOAManagementSystemNewApi.Model;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

namespace GYCTOAManagementSystemNewApi.Service
{
    public class AuditRuleService
    {
        #region GetAuditRule
        /// <summary>
        /// 根据用户id和模块编号，查找相应的审批规则
        /// </summary>
        /// <param name="sw">时间计时器</param>
        /// <param name="ALLUserList">获取所有人员信息</param>
        /// <param name="ALLAuditRuleList">获取所有审批流程</param>
        /// <param name="ModuleNumber">模块编号</param>
        /// <param name="SponsorUserid">数据对应用户id</param>
        /// <returns></returns>
        public static AuditRule GetAuditRule( List<Users> ALLUserList, List<AuditRule> ALLAuditRuleList, string ModuleNumber, int SponsorUserid)
        {
            AuditRule auditrule = null;
            var user = ALLUserList.Where(x => x.Id == SponsorUserid).FirstOrDefault();
            if (user == null) return auditrule;
            List<AuditRule> auditRules = ALLAuditRuleList.Where(x => !x.Delete && x.ModuleNumber == ModuleNumber).ToList();
            foreach (var a in auditRules)
            {
                if (a.SponsorUser != null && a.SponsorUser.Split(',').Contains(SponsorUserid.ToString()))
                {
                    auditrule = a;
                    break;
                }
            }
            //if (auditrule == null)
            //{
            //    foreach (var a in auditRules)
            //    {
            //        if (a.SponsorDepart != null && a.SponsorDepart.Split(',').Contains(user.DepartmentId.ToString()))
            //        {
            //            auditrule = a;
            //            break;
            //        }
            //    }
            //}
            return auditrule;
        }
        #endregion

    }




}
